package redis

import (
	goRedis "github.com/gomodule/redigo/redis"
)

type str struct {
	conn goRedis.Conn
}

func (s *str) Set(key string, value string, config ...interface{}) {
	val := []interface{}{key, value}
	s.conn.Do("set", val...)
	defer s.conn.Close()
}

func (s *str) SetEx(key, value string, expire int64) error {
	_, err := s.conn.Do("SETEX", key, expire, value)
	defer s.conn.Close()
	return err
}

func (s *str) Get(key string) string {
	val, _ := s.conn.Do("GET", key)
	defer s.conn.Close()
	if val == nil {
		return ""
	}
	return string(val.([]byte))
}

func (s *str) Exists(val string) bool {
	key := &key{
		connect: s.conn,
	}
	return key.Exists(val)
}

func (s str) DelKey(key string) {
	s.Set("del", key)
}
